﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ElectronicsMarket.Service.IService;
using ElectronicsMarket.Service.Models;


namespace ElectronicsMarket.Service.ServiceImpl
{
    public class BillboardImpl:IBillboardServcies
    {
        ElectronicsMarketDBClassesDataContext eMEntity;

        public BillboardImpl()
        {
            eMEntity = new ElectronicsMarketDBClassesDataContext();
        }
        public List<BILLBOAD> getAllBillboard()
        {
            List<BILLBOAD> bill = eMEntity.BILLBOADs.ToList();
            return bill;
        }
        public void insertBillboard(BILLBOAD billboard)
        {
            eMEntity.BILLBOADs.InsertOnSubmit(billboard);

            eMEntity.SubmitChanges();

        }
        public void deleteBillboard(BILLBOAD billboard)
        {
            BILLBOAD bill = eMEntity.BILLBOADs.Single(b => b.BILLBOAD_ID == billboard.BILLBOAD_ID);
            eMEntity.BILLBOADs.DeleteOnSubmit(bill);

            eMEntity.SubmitChanges();
        }
        public void updateBillboard(BILLBOAD billboard)
        {
            BILLBOAD bill = eMEntity.BILLBOADs.Single(b => b.BILLBOAD_ID == billboard.BILLBOAD_ID);

            bill.BILLBOAD_DESCRIPTION = billboard.BILLBOAD_DESCRIPTION;
            bill.BILLBOAD_IMAGE = billboard.BILLBOAD_IMAGE;
            bill.BILLBOAD_LINK_TO = billboard.BILLBOAD_LINK_TO;
            bill.BILLBOAD_NAME = billboard.BILLBOAD_NAME;
            bill.BILLBOAD_POSTED_AT = billboard.BILLBOAD_POSTED_AT;
            bill.BILLBOAD_STAFF_ID = billboard.BILLBOAD_STAFF_ID;

            eMEntity.SubmitChanges();
        }
        public long getLastBillboardiId()
        {
            if (eMEntity.BILLBOADs.ToList() == null)
                return 0;
            else
            {
                return eMEntity.BILLBOADs.OrderByDescending(o => o.BILLBOAD_ID).Select(o => o).First().BILLBOAD_ID;
            }
        }
    }
}